package cn.kgc.mes.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.kgc.mes.common.annotation.Log;
import cn.kgc.mes.common.core.controller.BaseController;
import cn.kgc.mes.common.core.domain.AjaxResult;
import cn.kgc.mes.common.enums.BusinessType;
import cn.kgc.mes.domain.CheckMachinery;
import cn.kgc.mes.service.ICheckMachineryService;
import cn.kgc.mes.common.utils.poi.ExcelUtil;
import cn.kgc.mes.common.core.page.TableDataInfo;

/**
 * 点检设备Controller
 * 
 * @author ruoyi
 * @date 2025-09-16
 */
@RestController
@RequestMapping("/checkmachinery/checkmachinery")
public class CheckMachineryController extends BaseController
{
    @Autowired
    private ICheckMachineryService checkMachineryService;

    /**
     * 查询点检设备列表
     */
//    @PreAuthorize("@ss.hasPermi('checkmachinery:checkmachinery:list')")
    @GetMapping("/list")
    public TableDataInfo list(CheckMachinery checkMachinery)
    {
        startPage();
        List<CheckMachinery> list = checkMachineryService.selectCheckMachineryList(checkMachinery);
        return getDataTable(list);
    }

    /**
     * 导出点检设备列表
     */
//    @PreAuthorize("@ss.hasPermi('checkmachinery:checkmachinery:export')")
    @Log(title = "点检设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CheckMachinery checkMachinery)
    {
        List<CheckMachinery> list = checkMachineryService.selectCheckMachineryList(checkMachinery);
        ExcelUtil<CheckMachinery> util = new ExcelUtil<CheckMachinery>(CheckMachinery.class);
        util.exportExcel(response, list, "点检设备数据");
    }

    /**
     * 获取点检设备详细信息
     */
//    @PreAuthorize("@ss.hasPermi('checkmachinery:checkmachinery:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(checkMachineryService.selectCheckMachineryByRecordId(recordId));
    }

    /**
     * 新增点检设备
     */
//    @PreAuthorize("@ss.hasPermi('checkmachinery:checkmachinery:add')")
    @Log(title = "点检设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CheckMachinery checkMachinery)
    {
        return toAjax(checkMachineryService.insertCheckMachinery(checkMachinery));
    }

    /**
     * 修改点检设备
     */
//    @PreAuthorize("@ss.hasPermi('checkmachinery:checkmachinery:edit')")
    @Log(title = "点检设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CheckMachinery checkMachinery)
    {
        return toAjax(checkMachineryService.updateCheckMachinery(checkMachinery));
    }

    /**
     * 删除点检设备
     */
//    @PreAuthorize("@ss.hasPermi('checkmachinery:checkmachinery:remove')")
    @Log(title = "点检设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(checkMachineryService.deleteCheckMachineryByRecordIds(recordIds));
    }
}
